Conditions | 4 |
Total Lines | 31 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import type { |
||
29 | |||
30 | function mapping< |
||
31 | Source extends CssModule, |
||
32 | Target extends AnyObject, |
||
33 | Mapping extends ClassNamesMap<OmitIndexed<GetProps<Target>>, Source> |
||
34 | >( |
||
35 | source: Source, |
||
36 | _: Target, |
||
37 | map: Mapping |
||
38 | ): {[M in keyof Mapping]: string} { |
||
39 | // TODO #33 change to for-in https://jsbench.me/prkm3gn4ji |
||
40 | const keys = $keys(map) as (keyof Mapping)[] |
||
41 | // TODO = {...keys} + reassign or delete? |
||
42 | , classnames = {} as {[M in keyof Mapping]: string} |
||
43 | |||
44 | for (let i = keys.length; i--;) { |
||
45 | const key = keys[i] |
||
46 | , val = map[key] |
||
47 | |||
48 | if (val === undefined) |
||
49 | continue |
||
50 | |||
51 | classnames[key] = typeof val === "function" |
||
52 | ? `${val}` |
||
53 | : resolver(source, |
||
54 | //@ts-expect-error #27 TS doesn't understand that ClassNaming is first of all function |
||
55 | val |
||
56 | ).join(" ") |
||
57 | } |
||
58 | |||
59 | return classnames |
||
60 | } |
||
61 |